﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Jim.Core;

public static class ObjectExtension
{
    /// <summary>
    /// 判断对象是否为空
    /// </summary>
    /// <param name="str"></param>
    /// <returns></returns>
    public static bool IsNull(this object obj)
    {
        return obj == null;
    }
    /// <summary>
    /// 判断对象不为空
    /// </summary>
    /// <param name="obj"></param>
    /// <returns></returns>
    public static bool isNotNull(this object obj) => !obj.IsNull();

    /// <summary>
    /// 判断类型是原始类型
    /// Boolean,Byte,SByte,Int16,Int32,UInt16,UInt32,Int64,UInt64,IntPtr,UIntPtr,Char,Double,Single,string,decimal,float,枚举
    /// </summary>
    /// <param name="type"></param>
    /// <returns></returns>
    public static bool IsCommonType(this Type type)
    {
        return type.IsPrimitive || type.IsEnum || type.Equals(typeof(string))|| type.Equals(typeof(decimal)) || type.Equals(typeof(float));
    }

    /// <summary>
    /// 判断对象是原始类型
    /// </summary>
    /// <param name="obj"></param>
    /// <returns></returns>
    public static bool IsCommonType(this object obj)
    {
        return obj.GetType().IsCommonType();
    }

}
